import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPRECEIVE implements Runnable{
    private DatagramSocket datagramSocket;
    @Override
    public void run() {

        while (true) {
            byte message[] = new byte[1024];
            DatagramPacket datagramPacket = new DatagramPacket(message, message.length);

            try {
                datagramSocket.receive(datagramPacket);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            System.out.println(datagramPacket.getAddress() + " " + datagramPacket.getPort() + " " + new String(datagramPacket.getData(), 0, datagramPacket.getLength()));
        }
    }

    public UDPRECEIVE(DatagramSocket datagramSocket) {
        this.datagramSocket = datagramSocket;
    }
}
